/**
 * Created by LiH on 2018/1/6.
 */
import takeDefaultOptions from "../lib/takeDefaultOptions";
import MaskComponent from '../components/ZuiCoolShareMask'

let $vm;

export default {
  install(Vue){
    const Mask = Vue.extend(MaskComponent);

    if(!$vm){
      $vm = new Mask({
        el: document.createElement('div')
      });

      document.body.appendChild($vm.$el)
    }

    const defaults = takeDefaultOptions($vm);

    Vue.$ZCMask = {
      show(options = {}){
        if(typeof options === 'string'){
          $vm.title = options
        } else if (typeof options === 'object') {
          options = Object.assign({}, defaults, options);
          for(let i in options){
            if(options.hasOwnProperty(i)){
              $vm[i] = options[i]
            }
          }
        }
        $vm.visible = true;
      },

      hide(){
        $vm.visible = false;
      }
    };

    Vue.mixin({
      created(){
        this.$ZCMask = Vue.$ZCMask
      }
    })
  }
}
